#include "eltheme.h"
using namespace ThemeColor;

QColor ThemeColor::textColor = QColor(96, 98, 102);
QColor ThemeColor::textPrimaryColor = QColor(48, 49, 51);
QColor ThemeColor::textDisabledColor = QColor(192, 196, 204);

QColor ThemeColor::inputDisabledColor = QColor(240, 240, 240);

QColor ThemeColor::lineColor = QColor(220, 223, 230);
QColor ThemeColor::lineDisabledColor = QColor(220, 223, 230);

QColor ThemeColor::primaryColor = QColor(64, 158, 255);
QColor ThemeColor::primaryEnteredColor = QColor(102, 177, 255);
QColor ThemeColor::primaryShallowColor = QColor(236, 245, 255);
QColor ThemeColor::primaryDeepColor = QColor(58, 142, 230);
QColor ThemeColor::primaryDisabledColor = QColor(160, 207, 255);

const QColor &ThemeColor::successColor = QColor(103, 194, 58);
const QColor &ThemeColor::successEnteredColor = QColor(133, 206, 97);
const QColor &ThemeColor::successShallowColor = QColor(240, 249, 235);
const QColor &ThemeColor::successDeepColor = QColor(93, 175, 52);
const QColor &ThemeColor::successDisabledColor = QColor(179, 225, 157);

const QColor &ThemeColor::warningColor = QColor(230, 162, 60);
const QColor &ThemeColor::warningEnteredColor = QColor(235, 181, 99);
const QColor &ThemeColor::warningShallowColor = QColor(253, 246, 236);
const QColor &ThemeColor::warningDeepColor = QColor(207, 146, 54);
const QColor &ThemeColor::warningDisabledColor = QColor(243, 209, 158);

const QColor &ThemeColor::dangerColor = QColor(245, 108, 108);
const QColor &ThemeColor::dangerEnteredColor = QColor(247, 137, 137);
const QColor &ThemeColor::dangerShallowColor = QColor(254, 240, 240);
const QColor &ThemeColor::dangerDeepColor = QColor(221, 97, 97);
const QColor &ThemeColor::dangerDisabledColor = QColor(250, 182, 182);

const QColor &ThemeColor::infoColor = QColor(144, 147, 153);
const QColor &ThemeColor::infoEnteredColor = QColor(166, 169, 173);
const QColor &ThemeColor::infoShallowColor = QColor(244, 244, 245);
const QColor &ThemeColor::infoDeepColor = QColor(130, 132, 138);
const QColor &ThemeColor::infoDisabledColor = QColor(200, 201, 204);

ElTheme::ElTheme(Type type)
{
    setType(type);
}

ElTheme &ElTheme::setType(Type type)
{
    _type = type;
    switch (_type) {
    case Primary:
        _normalColor = primaryColor;
        _enteredColor = primaryEnteredColor;
        _shallowColor = primaryShallowColor;
        _deepColor = primaryDeepColor;
        _disabledColor = primaryDisabledColor;
        break;
    case Success:
        _normalColor = successColor;
        _enteredColor = successEnteredColor;
        _shallowColor = successShallowColor;
        _deepColor = successDeepColor;
        _disabledColor = successDisabledColor;
        break;
    case Warning:
        _normalColor = warningColor;
        _enteredColor = warningEnteredColor;
        _shallowColor = warningShallowColor;
        _deepColor = warningDeepColor;
        _disabledColor = warningDisabledColor;
        break;
    case Danger:
        _normalColor = dangerColor;
        _enteredColor = dangerEnteredColor;
        _shallowColor = dangerShallowColor;
        _deepColor = dangerDeepColor;
        _disabledColor = dangerDisabledColor;
        break;
    case Information:
        _normalColor = infoColor;
        _enteredColor = infoEnteredColor;
        _shallowColor = infoShallowColor;
        _deepColor = infoDeepColor;
        _disabledColor = infoDisabledColor;
        break;
    default:
        _enteredColor = primaryShallowColor;
        _normalColor = primaryColor;
        _shallowColor = primaryShallowColor;
        _deepColor = primaryDeepColor;
        break;
    }
    return *this;
}

ElTheme::Type ElTheme::type() const
{
    return _type;
}

QColor ElTheme::normalColor() const
{
    return _normalColor;
}

QColor ElTheme::enteredColor() const
{
    return _enteredColor;
}

QColor ElTheme::shallowColor() const
{
    return _shallowColor;
}

QColor ElTheme::deepColor() const
{
    return _deepColor;
}

QColor ElTheme::disabledColor() const
{
    return _disabledColor;
}

ElTheme::TriColor ElTheme::generateTriColor(const QColor &color)
{
    auto h = color.hsvHue();
    auto s = color.hsvSaturation();
    auto v = color.value();
    s -= 35;
    if (s < 0)
        s = 0;
    QColor enteredColor = QColor::fromHsv(h, s, v);
    s -= 60; // sub 60 more to get disabled saturation, totally 95 substracted
    if (s < 0)
        s = 0;
    QColor disabledColor = QColor::fromHsv(h, s, v);
    v -= 35;
    if (v < 0)
        v = 0;
    QColor pressedColor = QColor::fromHsv(h, color.hsvSaturation(), v);
    return ElTheme::TriColor(enteredColor, pressedColor, disabledColor);
}

void ElTheme::togglePrimaryColor(const QColor &color)
{
    auto tri = generateTriColor(color);
    ThemeColor::primaryColor = color;
    ThemeColor::primaryEnteredColor = std::get<0>(tri);
    ThemeColor::primaryDeepColor = std::get<1>(tri);
    ThemeColor::primaryDisabledColor = std::get<2>(tri);
}
